package com.io;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class CountMain {
    public static void main(String[] args) {
        byte[] data = "hello".getBytes(StandardCharsets.UTF_8);
        try(CountInputStream in = new CountInputStream(new ByteArrayInputStream(data))) {
            int n;
            while ((n = in.read()) != -1) {
                System.out.println(n);
            }
            in.close();
            System.out.println("Total read " + in.getBytesRead() + " bytes");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
